package com.tnl.app.dao;

import java.util.List;

import org.springframework.stereotype.Repository;

import com.tnl.app.entity.Adcarousel;
import com.tnl.base.BaseDAO;

@Repository
public class AdcarouselDAO {
	private static final String SQL_GET_ID = "select * from tb_adcarousel  where id = ?";
	private static final String SQL_GET_TYPE = "select a.image_url,a.link,a.content,a.name,b.width,b.height from tb_adcarousel a LEFT JOIN tb_adcarousel_position b on a.ad_position_id=b.id where a.media_type = ? and a.enabled=1 and a.ad_position_id=1";
	private static final String SQL_GET_TYPE_CONTENT = "SELECT * from tb_adcarousel where media_type=? and ad_position_id=0 and enabled=1";
	private static final String SQL_GET_ALL = "select * from tb_adcarousel ";

	public List<Adcarousel> getALL() {

		return BaseDAO.queryForList(Adcarousel.class, SQL_GET_ALL);

	}

	public Adcarousel getById(int Id) {
		return BaseDAO.queryForObject(Adcarousel.class, SQL_GET_ID, Id);
	}

	public List<Adcarousel> getByType(Integer type) {
		return BaseDAO.queryForList(Adcarousel.class, SQL_GET_TYPE, type);
	}

	public List<Adcarousel> getByContent(Integer type) {
		return BaseDAO.queryForList(Adcarousel.class, SQL_GET_TYPE_CONTENT, type);
	}

	final String SQL_GET_COMPANY_BY_VIDEO = "select id,media_type AS mediaType,name,link,image_url,content,end_time,enabled from tb_adcarousel where ad_position_id=? and media_type=?";

	public List<Adcarousel> getCompanyByVideo(int companyId, int media_type) {
		return BaseDAO.queryForList(Adcarousel.class, SQL_GET_COMPANY_BY_VIDEO, companyId, media_type);
	}
}
